package com.frogs.ucenter.v1.request;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.druid.util.StringUtils;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.exception.RequestIllegalException;
import com.frogs.system.web.api.request.Request;

public class SubAreaRequest extends Request {
	
	private String parentId;

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		
		//获取地区级联信息
		String parentId = requestInfo.getParameter(ApiUrlParamEnum.parentId.getParamName());
		Integer[] lengths = {2,4,6};
		List<Integer> lengthList = new ArrayList<Integer>();
		lengthList = Arrays.asList(lengths);
		
		try{
			Integer.parseInt(parentId);
		} catch(Exception e) {
			throw new RequestIllegalException("错误的参数，请确认");
		}
		
		if(StringUtils.isEmpty(parentId) || 
				(!parentId.equals("0") && !lengthList.contains(parentId.length()))){
			throw new RequestIllegalException("缺少必要参数，请确认");
		}
		setParentId(parentId);
	}

}
